#include <stdio.h>
#include <stdlib.h>

#define MAXLINE     1024

int main(int argc, char *argv[])
{
    char line[MAXLINE];
    FILE *fp;

    if (argc != 2)
    {
        fprintf(stderr, "usage: %s <cmd>\n", argv[0]);
        exit(0);
    }

    if ((fp = popen(argv[1], "r")) < 0)
    {
        perror("popen error");
        exit(0);
    }
    
    while (fgets(line, MAXLINE, fp) != NULL)
        fputs(line, stdout);

    if (ferror(fp))
    {
        perror("fgets error");
        exit(0);
    }

    return 0;
}
